Allow build scripts to specify dependencies
authorAlex Crichton <alex@alexcrichton.com>
Wed, 11 Nov 2015 00:39:15 +0000 (16:39 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 11 Nov 2015 21:53:17 +0000 (13:53 -0800)
commit7c97c5bf694df1a67603e4806accd2bef88635ee
tree12898b8e94d9214741cab478deea80b2e1ac75df
parent6026a186422d942188f1e979cfd6b1001de8098c
Allow build scripts to specify dependencies

Currently Cargo is quite conservative in how it determines whether a build
script should be run. The heuristic used is "did any file in the project
directory change", but this is almost always guaranteed to be too coarse
grained in situations like:

* If the build script takes a long time to run it's advantageous to run it as
  few times as possible. Being able to inform Cargo about precisely when a build
  script should be run should provide more robust support here.
* Build scripts may not always have all of their dependencies in-tree or in the
  crate root. Sometimes a dependency could be elsewhere in a repository and
  scripts need a method of informing Cargo about this (as currently these
  compiles don't happen then they should).

This commit adds this support in build scripts via a new `rerun-if-changed`
directive which can be printed to standard output (using the standard Cargo
metadata format). The value for this key is a path relative to the crate root,
and Cargo will only look at these paths when determining whether to rerun the
build script. Any other file changes will not trigger the build script to be
rerun.

Future extensions could possibly include the usage of glob patterns in build
script paths like the `include` and `exclude` features of `Cargo.toml`, but
these should be backwards compatible to add in the future.

Closes #1162
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_rustc/context.rs
src/cargo/ops/cargo_rustc/custom_build.rs
src/cargo/ops/cargo_rustc/fingerprint.rs
src/doc/build-script.md
tests/test_cargo_compile_custom_build.rs